package com.poetize.plus.entity.vo;

import com.poetize.plus.entity.po.Article;
import com.poetize.plus.entity.po.Label;
import com.poetize.plus.entity.po.Sort;
import io.swagger.v3.oas.annotations.media.Schema;

import java.util.ArrayList;
import java.util.List;

/**
 * @author zuosy
 * @created 2024/4/3 13:46
 */
@Schema(description = "下拉框VO")
public record SelectVO(
        @Schema(description = "key")
        Long key,

        @Schema(description = "value")
        String value
) {
    /**
     * 标签集合转下拉框
     *
     * @return
     */
    public static List<SelectVO> convertLabelSelect(List<Label> labelList) {
        List<SelectVO> result = new ArrayList<>();
        labelList.forEach(label -> {
            SelectVO vo = new SelectVO(label.getLabelId(), label.getLabelName());
            result.add(vo);
        });
        return result;
    }

    /**
     * 标签集合转下拉框
     *
     * @return
     */
    public static List<SelectVO> convertSortSelect(List<Sort> sortList) {
        List<SelectVO> result = new ArrayList<>();
        sortList.forEach(sort -> {
            SelectVO vo = new SelectVO(sort.getSortId(), sort.getSortName());
            result.add(vo);
        });
        return result;
    }

    /**
     * 文章集合转下拉框
     *
     * @return
     */
    public static List<SelectVO> convertArticleSelect(List<Article> articleList) {
        List<SelectVO> result = new ArrayList<>();
        articleList.forEach(article -> {
            SelectVO vo = new SelectVO(article.getId(), article.getArticleTitle());
            result.add(vo);
        });
        return result;
    }
}
